#ifndef LOGICPOOL_H
#define LOGICPOOL_H

#include <stdint.h>
#include "LogicPool/LogicInterface.h"
#include "LogicPool/LogicLevel.h"

class LogicPool 
{
  public:
  
    static const uint8_t level_low;
    static const uint8_t level_high;
    static const uint8_t level_pulse;
    static const uint8_t level_nc;

  protected:

    LogicInterface & logicpool;
    uint8_t type;
    uint8_t number;
    uint8_t channel;
    
    void SetAddress(uint8_t addr)
    {
        logicpool.SetAddress(type, number, addr);
    };
  
  
  public:
  
    LogicPool(LogicInterface & iinterface, uint8_t itype, uint8_t inumber = 1) 
        : logicpool(iinterface), type(itype), number(inumber), channel(0) {};

    uint8_t GetOutput(int no) 
    {
        SetAddress(no);
        return logicpool.ReadByte();
    };

    void SetInput(int inputno, uint8_t output) 
    { 
        SetAddress(inputno);
        logicpool.WriteByte(output);
    };

/*
    void SetInput(uint8_t output) 
    { 
        SetInput(0, output); 
    };
*/
  
    void SetInput(LogicPool & output, uint8_t no_out = 0) 
    {
        SetInput(output.GetOutput(no_out));
    };
  
    void SetInput(uint8_t no_in, LogicPool & output, uint8_t no_out = 0) 
    {
        SetInput(no_in, output.GetOutput(no_out));
    };
    
    LogicPool & operator << (LogicPool & logicout) 
    {
        SetInput(logicout.GetOutput());
        return * this;
    };

    LogicPool & operator << (LogicPool * logicout) 
    {
        SetInput(logicout->GetOutput());
        return * this;
    };

    LogicPool & operator >> (LogicPool & logicin) 
    {
        logicin.SetInput(GetOutput());
        return logicin;
    };

    LogicPool & operator << (LogicLevel & logiclevel) 
    {
        SetInput(logiclevel.GetLevel());
        return * this;
    };

    LogicPool & operator << (LogicLevel * logiclevel) 
    {
        SetInput(logiclevel->GetLevel());
        return * this;
    };

    uint8_t GetOutput() 
    {
        return GetOutput(channel);
        channel = 0;
    };
    
    void SetInput(uint8_t output) 
    { 
        SetInput(channel, output); 
        channel = 0;
    };

    LogicPool & Channel(uint8_t ichannel) 
    {
        channel = ichannel;
        return * this;
    };

};

#endif

